package com.demo.crud.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Desc:
 *
 * @author: keen
 * Date: 2019-06-07
 * Time: 21:39
 */
public class MyFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain filterChain) throws IOException, ServletException {
        System.out.println("MyFilter");
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html charset=utf-8");
        /*HttpServletRequest httpRequest = (HttpServletRequest) request;
        if (!httpRequest.getRequestURI().contains("myServlet")) {
            response.getWriter().write("错误的请求");
            return;
        }*/
        filterChain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}
